import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.0
import QtQuick.XmlListModel 2.0

Rectangle {
    id: componentSplitter

    state: "vertical"
    width: 5
    height: 5
    color: "gray"

    property int minimumDrag: -1
    property int maximumDrag: -1


    MouseArea {
        id: mouseAreaSplitter
        anchors.fill: parent
        drag.target: componentSplitter

    }
    
    states: [
        State {
            name: "vertical"
            AnchorChanges {
                target: componentSplitter
                anchors.top: componentSplitter.parent.top
                anchors.bottom: componentSplitter.parent.bottom
                anchors.right: undefined
                anchors.left: undefined
            }

            PropertyChanges {
                target: mouseAreaSplitter
                drag.axis: Drag.XAxis
                cursorShape: Qt.SplitHCursor
                drag.minimumX: componentSplitter.minimumDrag < 0 ? 0 : componentSplitter.minimumDrag
                drag.maximumX: componentSplitter.maximumDrag < 0 ? componentSplitter.parent.width : componentSplitter.maximumDrag
                enabled: true
            }
        },

        State {
            name: "horizontal"
            AnchorChanges {
                target: componentSplitter
                anchors.top: undefined
                anchors.bottom: undefined
                anchors.right: componentSplitter.parent.right
                anchors.left: componentSplitter.parent.left
            }

            PropertyChanges {
                target: mouseAreaSplitter
                drag.axis: Drag.YAxis
                cursorShape: Qt.SplitVCursor
                drag.minimumY: componentSplitter.minimumDrag < 0 ? 0 : componentSplitter.minimumDrag
                drag.maximumY: componentSplitter.maximumDrag < 0 ? componentSplitter.parent.height : componentSplitter.maximumDrag
                enabled: true
            }
        },

        State {
            name: "fixedVertical"
            AnchorChanges {
                target: componentSplitter
                anchors.top: componentSplitter.parent.top
                anchors.bottom: componentSplitter.parent.bottom
                anchors.right: undefined
                anchors.left: undefined
            }

            PropertyChanges {
                target: mouseAreaSplitter
                enabled: false
                cursorShape: Qt.ArrowCursor
                opacity: 0.5
            }
        },

        State {
            name: "fixedHorizontal"
            AnchorChanges {
                target: componentSplitter
                anchors.top: undefined
                anchors.bottom: undefined
                anchors.right: componentSplitter.parent.right
                anchors.left: componentSplitter.parent.left
            }

            PropertyChanges {
                target: mouseAreaSplitter
                enabled: false
                cursorShape: Qt.ArrowCursor
                opacity: 0.5
            }
        }

    ]
}
